/**
 * Scalog - Scalog is a logging framework for the Scala programming language.
 * Copyright (C) 2009  Laurent Grangier
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.scalog.log4j

import net.scalog._;
import net.scalog.appender.Appender;

import org.apache.log4j.LogManager;
import org.apache.log4j.{Level => Log4JLevel};
import org.apache.log4j.spi.LoggingEvent;

/**
 * Appender which delegates the responsibility to Log4J appenders.
 * 
 * @author Laurent Grangier
 */
class Log4JAppender extends Appender {

  def doAppend(logMessage : LogMessage) : Unit = {
    val log4jLogger = LogManager.getLogger(logMessage.logger.name);
    val loggingEvent = new LoggingEvent(logMessage.logger.name, 
                                        log4jLogger, 
                                        logMessage.timestamp,
                                        Log4JHelper.getLevel(logMessage.level), 
                                        logMessage.message, 
                                        logMessage.throwable);
    log4jLogger.callAppenders(loggingEvent);
  }
  
}
